package com.etone.smartAudit.controller;


import com.etone.smartAudit.commService.CommPUumOrganizationinfoService;
import com.etone.smartAudit.commService.CommPUumUserinfoService;
import com.etone.smartAudit.dto.PageDTO;
import com.etone.smartAudit.error.CustomParameterizedException;
import com.etone.smartAudit.service.PUumOrganizationinfoService;
import com.etone.smartAudit.service.PUumUserinfoService;
import com.etone.smartAudit.vo.PUumOrgVO;
import com.etone.smartAudit.vo.PUumUserinfoVO;
import com.etone.smartAudit.vo.PagerVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "portal组织用户", value = "PUumUserinfoController")
public class PUumUserinfoController {

    @Autowired
    private PUumUserinfoService pUumUserinfoService;

    @Autowired
    private PUumOrganizationinfoService organizationinfoService;

    @Autowired
    private CommPUumUserinfoService  commPUumUserinfoService;


    @ApiOperation(value = "portal用户组织")
    @GetMapping("/portal/users")
    public PagerVO<PUumUserinfoVO> getUsers(PageDTO pageDTO) {
        return commPUumUserinfoService.getUsersPage(pageDTO);
    }


    @ApiOperation(value = "portal 获取公司下面所有人员")
    @GetMapping("/portal/companyUsers")
    public PagerVO<PUumUserinfoVO> getCompanyUsers(PageDTO pageDTO) {
        return commPUumUserinfoService.getCompanyUsers(pageDTO);
    }


    @ApiOperation(value = "portal用户组织树，树形结构返回")
    @GetMapping("/portal/usersTree")
    public List<PUumOrgVO> usersTree(PageDTO pageDTO) {
        return commPUumUserinfoService.usersTree(pageDTO);
    }


    @ApiOperation(value = "同步用户")
    @GetMapping("/portal/synUser")
    public void syncUser() {
        try {
            pUumUserinfoService.synUserInfo();
        } catch (Exception e) {
            log.error("同步用户失败", e);
            throw new CustomParameterizedException("同步用户失败");
        }
    }

    @ApiOperation(value = "同步组织")
    @GetMapping("/portal/synOrg")
    public void syncUserOrg() {
        try {
            organizationinfoService.synOrgnization();
        } catch (Exception e) {
            log.error("同步用户失败", e);
            throw new CustomParameterizedException("同步用户失败");
        }
    }

    @ApiOperation(value = "获取用户组织树")
    @GetMapping("/portal/orgTree")
    public List<PUumOrgVO> getUserOrg() {
        return commPUumUserinfoService.getUserOrg();
    }

    @ApiOperation(value = "获取用户组织平级获取")
    @GetMapping("/portal/orgList")
    public List<PUumOrgVO> getOrgList(@ApiParam("父级Id,不传为获取顶层组织") String parentId) {
        return commPUumUserinfoService.getOrgList(parentId);
    }
}
